import { defineStore } from 'pinia'
import defaultAvatarFemale from '@/assets/touxiang-nv.svg'
import defaultAvatarMale from '@/assets/touxiangnan.svg'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: null
  }),
  
  actions: {
    setUserInfo(info) 
    {
      this.userInfo = info
    },
    
    clearUserInfo() 
    {
      this.userInfo = null
    }
  },

  getters: {
    // 获取显示名称（如果太长则截断）
    displayName: (state) => {
      if (!state.userInfo?.name) return ''
      return state.userInfo.name.length > 6 
        ? state.userInfo.name.substring(0, 6) + '...'
        : state.userInfo.name
    },
    
    // 获取头像（根据性别返回不同的默认头像）
    avatarUrl: (state) => {
      return state.userInfo?.sex === '女' 
        ? defaultAvatarFemale  // 需要添加默认女性头像
        : defaultAvatarMale    // 需要添加默认男性头像
    }
  }
}) 